﻿
using System.Reflection.Metadata.Ecma335;
using System.Text;

namespace PCH.Services
{
    public class CommonService : ICommonService
    {
        private readonly ILogger<CommonService> _logger;
        public CommonService(ILogger<CommonService> logger)
        {
            _logger= logger;
        }

        // 读取AmisSchema  文件路径： AmisSchema.home-view.json
        public async Task<string> GetResourceStringAsync(string sourceName)
        {
//#if DEBUG
            var names = sourceName.Split('.');
            var resourceFile = Path.Combine(Directory.GetCurrentDirectory(), names[0], names[1])+"."+names.Last();
            _logger.LogInformation(resourceFile);
            if (File.Exists(resourceFile))
            {
                return File.ReadAllText(resourceFile, Encoding.UTF8);
            }
            else
            {
                return await Task.FromResult(string.Empty);
            }
//#else
//            var assembly = System.Reflection.Assembly.GetExecutingAssembly();
//            var resourceName = $"{assembly.GetName().Name}.{sourceName}";
//            using var stream = assembly.GetManifestResourceStream(resourceName);
//            if (stream != null)
//            {
//                using var reader = new StreamReader(stream, Encoding.UTF8);
//                return await reader.ReadToEndAsync();
//            }
//            return string.Empty;
//#endif
        }

        public AmisRes GetAmisRes()
        {
            return new AmisRes();
        }
    }
}
